#include "shop.h"
#include <string>

void shop::loaddatabase(std::string userdata, std::string itemdata, std::string logdata)
{
    users.loaddatabase(userdata);
    items.loaddatabase(itemdata);
    mozhu::log::Get()->loaddatabase(logdata);
}

void shop::unloaddatabase()
{
    users.unloaddatabase();
    items.unloaddatabase();
    mozhu::log::Get()->unloaddatabase();
}

void shop::mainpage()
{
	mozhu::log::Get()->writelog(1, "进入系统主页");
    std::vector<_UI> page;

    _UI tittle;
    tittle.type = UI_str;
    tittle.addconststring("欢迎使用超市收银系统",1,6);
    page.emplace_back(tittle);
    
    _UI selector;
    selector.type = UI_selector;
    selector.specialSelector = -1;
    selector.selectNum = 0;
    selector.addconststring("开始结算",1);
    selector.addconststring("库存管理",1);
    selector.addconststring("顾客管理",1);
    selector.addconststring("订单日志",1);
    selector.addconststring("资金统计",1);
    selector.addconststring("系统日志",1);
    selector.addconststring("退出系统",1);
    page.emplace_back(selector);

    while(1)
    {
        clearUI();
        PrintUI(page);

        int m_key_pressed = KeyboardOperate();
        if(m_key_pressed == KEY_UP)
        {
            if(page[1].selectNum == 0)
                page[1].selectNum = page[1].data.size() - 1;
            else
                page[1].selectNum -= 1;
        }
        else if(m_key_pressed == KEY_DOWN)
        {
            if(page[1].selectNum == page[1].data.size() - 1)
                page[1].selectNum = 0;
            else
                page[1].selectNum += 1;
        }
        else if(m_key_pressed == KEY_ESC)
        {
            mozhu::log::Get()->writelog(2, "退出系统");
            unloaddatabase();
            return;
        }
        else        
        {
            if(page[1].selectNum == 0)
            {
                orderpage();
            }
            else if(page[1].selectNum == 1)
            {
                inventorypage();
            }
            else if(page[1].selectNum == 2)
            {
                custommanagepage();
            }
            else if(page[1].selectNum == 3)
            {
                orderhistorypage();
            }
            else if(page[1].selectNum == 4)
            {
                orderstasticspage();
            }
            else if(page[1].selectNum == 5)
            {
                systemlogpage();
            }
            else if(page[1].selectNum == 6)
            {
                unloaddatabase();
                return;
            }
        }
    }
}

void shop::orderpage()
{
    mozhu::log::Get()->writelog(1, "进入结账页面");
    std::vector<_UI> page;
    order m_order;
    std::string userid = "客户未登陆";
    user* n_user = nullptr;
    float totalprice = 0;

    _UI tittle;
    tittle.type = UI_str;
    tittle.addconststring("结账页面",1,6);
    tittle.addconststring("选中商品后可修改商品数量，输入0即为删除商品",1);
    tittle.addconststring("当前总价格：");
    tittle.addfloat(&totalprice,1);
    tittle.addconststring("已添加商品：",1);
    page.emplace_back(tittle);

    _UI selector;
    selector.type = UI_selector;
    selector.specialSelector = -1;
    selector.selectNum = 0;
    selector.addconststring("客户ID:");
    selector.addstr(&userid,1);
    selector.addconststring("添加商品",1);
    selector.addconststring("取消订单",1);
    selector.addconststring("提交订单",1);
    page.emplace_back(selector);

    while(1)
    {
        totalprice = 0;
        page[1].clear();
        page[1].addconststring("客户ID:");
        page[1].addstr(&userid,1);
        page[1].addconststring("添加商品",1);
        page[1].addconststring("取消订单",1);
        page[1].addconststring("提交订单",1);
        for(int i = 0; i < m_order.data.size();i++)
        {
            page[1].addconststring("名称：");
            page[1].addstr(&m_order.data[i].ptr->name);
            page[1].addconststring("  数量：");
            page[1].addint(&m_order.data[i].number);
            page[1].addconststring("  单价:");
            page[1].addfloat(&m_order.data[i].ptr->price,1);
            totalprice += m_order.data[i].number * m_order.data[i].ptr->price;
        }
        
        clearUI();
        PrintUI(page);

         int m_key_pressed = KeyboardOperate();
        if(m_key_pressed == KEY_UP)
        {
            if(page[1].selectNum == 0)
                page[1].selectNum = page[1].data.size() - 2;
            else
                page[1].selectNum -= 1;
        }
        else if(m_key_pressed == KEY_DOWN)
        {
            if(page[1].selectNum == page[1].data.size() - 2)
                page[1].selectNum = 0;
            else
                page[1].selectNum += 1;
        }
        else if(m_key_pressed == KEY_ESC)
        {
            mozhu::log::Get()->writelog(0, "订单取消了");
            return;
        }
        else        
        {
            if(page[1].selectNum == 0)
            {
                std::cout << "请输入用户ID：";
                std::string m_user_ID;
                std::cin >> m_user_ID;

                if(m_user_ID == "-1")
                {
                    n_user = users.newuser();
                    userid = n_user->ID;
                    mozhu::log::Get()->writelog(0, "注册了ID是"+userid+"的新用户");
                }
                else if(users.finduser(m_user_ID, n_user))
                {
                    userid = n_user->ID;
                }
                
            }
            else if(page[1].selectNum == 1)
            {
                std::cout << "请输入商品编号：";
                std::string m_item_ID;
                std::cin >> m_item_ID;
                if(!m_item_ID.empty())
                {
                    item* ptr = nullptr;
                    if(items.finditem(m_item_ID,ptr))
                    {
                        m_order.additem(ptr);
                        std::string loginfo = "订单中添加了";
                        loginfo = loginfo + ptr->name;
                        mozhu::log::Get()->writelog(0, loginfo);
                    }
                }
            }
            else if(page[1].selectNum == 2)
            {
                mozhu::log::Get()->writelog(0, "订单取消了");
                return;
            }
            else if(page[1].selectNum == 3)
            {
                if(m_order.data.size() == 0)
                {
                    clearUI();
                    std::cout << "订单内容不可为空\n按上操作键继续";
                    while(1)
                    {
                        if(KeyboardOperate() == KEY_UP)
                            break;
                    }

                }
                else if (n_user == nullptr) 
                {
                    clearUI();
                    std::cout << "客户未登陆\n按上操作键继续";
                    while(1)
                    {
                        if(KeyboardOperate() == KEY_UP)
                            break;
                    }
                }
                else 
                {
                    float price = 0;
                    for(ordercell m_cell : m_order.data)
                    {
                        price += m_cell.ptr->price;
                    }
                    m_order.totalprice = price * n_user->getrate();
                    m_order.rate = n_user->getrate();
                    m_order.customer=n_user;
                    n_user->gainpoint(m_order.totalprice);

                    for(ordercell temp : m_order.data)
                    {
                        temp.ptr->number  = temp.number;
                        temp.databackup = *temp.ptr;
                    }
                    orders.addorder(m_order);


                    if(m_order.totalprice > 2000)
                    {
                        if(n_user->getlevel() == userlevel::normuser)
                        {
                            n_user->levelup();
                            n_user->levelup();
                            clearUI();
                            std::cout << "顾客已升级，请补充信息，按上方向键继续\n";
                            while(1)
                            {
                                if(KeyboardOperate() == KEY_UP)
                                    break;
                            }
                            adddatapage(n_user);
                            mozhu::log::Get()->writelog(0, "顾客"+n_user->ID+"升级到SVIP");
                        }
                    }
                    else if(m_order.totalprice > 1000)
                    {
                        if(n_user->getlevel() == userlevel::normuser)
                        {
                            n_user->levelup();
                            std::cout << "顾客已升级，请补充信息，按上方向键继续\n";
                            while(1)
                            {
                                if(KeyboardOperate() == KEY_UP)
                                    break;
                            }
                            adddatapage(n_user);
                            mozhu::log::Get()->writelog(0, "顾客"+n_user->ID+"升级到VIP");
                        }
                        else if(n_user->getlevel() == userlevel::vip)
                        {
                            n_user->levelup();
                            std::cout << "顾客已升级，按上方向键继续\n";
                            while(1)
                            {
                                if(KeyboardOperate() == KEY_UP)
                                    break;
                            }
                            mozhu::log::Get()->writelog(0, "顾客"+n_user->ID+"升级到SVIP");
                        }
                    }
                }
                
                {
                    clearUI();
                    std::cout << "订单完成，按上方向键退出\n";
                    while(1)
                    {
                        if(KeyboardOperate() == KEY_UP)
                            break;
                    }
                    return;
                }
            }
            else 
            {
                std::cout << "请输入数量";
                int tempNum = 0;
                std::cin >> tempNum;
                if(tempNum == 0)
                {
                    m_order.data.erase(m_order.data.begin() + page[1].selectNum - 3);
                }
                else
                {
                    if(tempNum > m_order.data[page[1].selectNum - 4].ptr->number)
                    {
                        clearUI();
                        std::cout << "目前库存数量:" << m_order.data[page[1].selectNum - 4].ptr->number <<std::endl;
                        std::cout << "购买数量不得大于目前库存数量，按上方向键继续\n";
                        while(1)
                        {
                            if(KeyboardOperate() == KEY_UP)
                                break;
                        }
                    }
                    else 
                    {
                        m_order.data[page[1].selectNum - 4].number = tempNum;
                    }
                    
                    mozhu::log::Get()->writelog(0, "订单商品ID" + m_order.data[page[1].selectNum - 4].ptr->ID + "购买数量修改为" + std::to_string(tempNum));
                }
            }
        }
    }
}

void shop::inventorypage()
{
    mozhu::log::Get()->writelog(1, "进入库存管理页面");
    std::vector<_UI> page;

    _UI tittle;
    tittle.type = UI_str;
    tittle.addconststring("库存页面",1,6);
    tittle.addconststring("选中项目后可修改商品库存，输入0即为删除项目");
    page.emplace_back(tittle);

    _UI selector;
    selector.type = UI_selector;
    selector.specialSelector = -1;
    selector.selectNum = 0;
    page.emplace_back(selector);

    while(1)
    {
        page[1].clear();
        page[1].addconststring("按名称筛选",1);
        page[1].addconststring("按剩余库存筛选",1);
        for(int i = 0; i < items.items.size();i++)
        {
            page[1].addconststring("商品名：");
            page[1].addstr(&items.items[i].name);
            page[1].addconststring(" ID：");
            page[1].addstr(&items.items[i].ID);
            page[1].addconststring("定价：");
            page[1].addfloat(&items.items[i].price);
            page[1].addconststring("库存：");
            page[1].addint(&items.items[i].number,1);
        }
        clearUI();
        PrintUI(page);

        int m_key_pressed = KeyboardOperate();
        if(m_key_pressed == KEY_UP)
        {
            if(page[1].selectNum == 0)
                page[1].selectNum = page[1].data.size() - 1;
            else
                page[1].selectNum -= 1;
        }
        else if(m_key_pressed == KEY_DOWN)
        {
            if(page[1].selectNum == page[1].data.size() - 1)
                page[1].selectNum = 0;
            else
                page[1].selectNum += 1;
        }
        else if(m_key_pressed == KEY_ESC)
        {
            mozhu::log::Get()->writelog(1, "退出库存管理");
            return;
        }
        else        
        {
            if(page[1].selectNum == 0)
            {
                selectitembyname();
            }
            else if(page[1].selectNum == 1)
            {
                selectitembynumber();
            }
            else if(items.items.size() != 0)
            {
                iteminfopage(&items.items[page[1].selectNum - 2]);
            }
        }
    }
}

void shop::selectitembyname()
{
    mozhu::log::Get()->writelog(1, "进入名称搜索页面");
    std::vector<_UI> page;
    std::string keyword;
    std::vector<item*> data;

    _UI tittle;
    tittle.type = UI_str;
    tittle.addconststring("搜索页面",1,6);
    page.emplace_back(tittle);

    _UI selector;
    selector.type = UI_selector;
    selector.specialSelector = -1;
    selector.selectNum = 0;
    selector.addconststring("关键词");
    selector.addstr(&keyword,1);
    page.emplace_back(selector);

    while(1)
    {
        clearUI();
        PrintUI(page);

        int m_key_pressed = KeyboardOperate();
        if(m_key_pressed == KEY_UP)
        {
            if(page[1].selectNum == 0)
                page[1].selectNum = page[1].data.size() - 1;
            else
                page[1].selectNum -= 1;
        }
        else if(m_key_pressed == KEY_DOWN)
        {
            if(page[1].selectNum == page[1].data.size() - 1)
                page[1].selectNum = 0;
            else
                page[1].selectNum += 1;
        }
        else if(m_key_pressed == KEY_ESC)
        {
            mozhu::log::Get()->writelog(1, "退出名称搜索");
            return;
        }
        else        
        {
            if(page[1].selectNum == 0)
            {
                std::cout << "请输入搜索关键词";
                std::cin >> keyword;
                if(!keyword.empty())
                {
                    data = items.gettarget(keyword);
                    page[1].clear();
                    page[1].addconststring("关键词");
                    page[1].addstr(&keyword,1);
                    for(item* m_temp_item_ptr : data)
                    {
                        page[1].addconststring("商品名：");
                        page[1].addstr(&m_temp_item_ptr->name);
                        page[1].addconststring(" ID：");
                        page[1].addstr(&m_temp_item_ptr->ID);
                        page[1].addconststring("定价：");
                        page[1].addfloat(&m_temp_item_ptr->price);
                        page[1].addconststring("库存：");
                        page[1].addint(&m_temp_item_ptr->number,1);
                    }
                }
            }
            else if (!data.empty())
            {
                iteminfopage(&items.items[page[1].selectNum - 1]);
            }
        }
    }
}

void shop::selectitembynumber()
{
    mozhu::log::Get()->writelog(1, "进入库存搜索页面");
    std::vector<_UI> page;
    int number;
    std::vector<item*> data;

    _UI tittle;
    tittle.type = UI_str;
    tittle.addconststring("搜索页面",1,6);
    page.emplace_back(tittle);

    _UI selector;
    selector.type = UI_selector;
    selector.specialSelector = -1;
    selector.selectNum = 0;
    selector.addconststring("最大库存量");
    selector.addint(&number,1);
    page.emplace_back(selector);

    while(1)
    {
        clearUI();
        PrintUI(page);

        int m_key_pressed = KeyboardOperate();
        if(m_key_pressed == KEY_UP)
        {
            if(page[1].selectNum == 0)
                page[1].selectNum = page[1].data.size() - 1;
            else
                page[1].selectNum -= 1;
        }
        else if(m_key_pressed == KEY_DOWN)
        {
            if(page[1].selectNum == page[1].data.size() - 1)
                page[1].selectNum = 0;
            else
                page[1].selectNum += 1;
        }
        else if(m_key_pressed == KEY_ESC)
        {
            mozhu::log::Get()->writelog(1, "退出库存搜索");
            return;
        }
        else        
        {
            if(page[1].selectNum == 0)
            {
                std::cout << "请输入搜索关键词";
                std::cin >> number;

                data = items.gettarget(number);
                page[1].clear();
                page[1].addconststring("关键词");
                page[1].addint(&number,1);
                for(item* m_temp_item_ptr : data)
                {
                    page[1].addconststring("商品名：");
                    page[1].addstr(&m_temp_item_ptr->name);
                    page[1].addconststring(" ID：");
                    page[1].addstr(&m_temp_item_ptr->ID);
                    page[1].addconststring("定价：");
                    page[1].addfloat(&m_temp_item_ptr->price);
                    page[1].addconststring("库存：");
                    page[1].addint(&m_temp_item_ptr->number,1);
                }
                
            }
            else if (!data.empty())
            {
                iteminfopage(&items.items[page[1].selectNum - 1]);
            }
        }
    }
}

void shop::iteminfopage(item* ptr)
{
    if(ptr == nullptr)
        return;
    mozhu::log::Get()->writelog(1, "进入货物详情页面");
    std::vector<_UI> page;

    _UI tittle;
    tittle.type = UI_str;
    tittle.addconststring("货物详情页",1,6);
    page.emplace_back(tittle);

    _UI selector;
    selector.type = UI_selector;
    selector.specialSelector = -1;
    selector.selectNum = 0;
    selector.addconststring("商品名：");
    selector.addstr(&ptr->name,1);
    selector.addconststring(" ID：");
    selector.addstr(&ptr->ID,1);
    selector.addconststring("定价：");
    selector.addfloat(&ptr->price,1);
    selector.addconststring("库存：");
    selector.addint(&ptr->number,1);
    page.emplace_back(selector);

    while(1)
    {
        clearUI();
        PrintUI(page);

        int m_key_pressed = KeyboardOperate();
        if(m_key_pressed == KEY_UP)
        {
            if(page[1].selectNum == 0)
                page[1].selectNum = page[1].data.size() - 1;
            else
                page[1].selectNum -= 1;
        }
        else if(m_key_pressed == KEY_DOWN)
        {
            if(page[1].selectNum == page[1].data.size() - 1)
                page[1].selectNum = 0;
            else
                page[1].selectNum += 1;
        }
        else if(m_key_pressed == KEY_ESC)
        {
            mozhu::log::Get()->writelog(1, "退出货物详情");
            return;
        }
        else        
        {
            if(page[1].selectNum == 0)
            {
                std::string middle;
                std::cout << "请输入新货物名";
                std::cin >> middle;
                if(!middle.empty())
                    ptr->name = middle;
            }
            else if(page[1].selectNum == 1)
            {
                clearUI();
                std::cout << "货物ID不可修改\n按上操作键继续";
                while(1)
                {
                    if(KeyboardOperate() == KEY_UP)
                        break;                   
                }
            }
            else if(page[1].selectNum == 2)
            {
                float middle;
                std::cout << "请输入新定价";
                std::cin >> middle;
                if(!(middle < 0))
                    ptr->price = middle;
            }
            else if(page[1].selectNum == 3)
            {
                int middle;
                std::cout << "请输入新库存数量";
                std::cin >> middle;
                if(!(middle < 0))
                    ptr->number = middle;
            }
        }
    }
}

void shop::custommanagepage()
{
    std::vector<_UI> page;
    mozhu::log::Get()->writelog(1, "进入顾客列表页面");

    _UI tittle;
    tittle.type = UI_str;
    tittle.addconststring("顾客详情页",1,6);
    page.emplace_back(tittle);

    _UI selector;
    selector.type = UI_selector;
    selector.specialSelector = -1;
    selector.selectNum = 0;
    page.emplace_back(selector);
    
    for (int i = 0;i < users.users.size();i++)
    {
        page[1].addconststring("用户名：");
        page[1].addstr(&users.users[i].name);
        page[1].addconststring(" ID：");
        page[1].addstr(&users.users[i].name);
        page[1].addconststring(" 会员等级：");
        if(users.users[i].getlevel() == normuser)
        {
            page[1].addconststring("普通顾客",1);
        }
        else if(users.users[i].getlevel() == vip)
        {
            page[1].addconststring("VIP",1);
        }
        else if(users.users[i].getlevel() == supervip)
        {
            page[1].addconststring("SuperVIP",1);
        }
    }   

    while(1)
    {
        clearUI();
        PrintUI(page);

        int m_key_pressed = KeyboardOperate();
        if(m_key_pressed == KEY_UP)
        {
            if(page[1].selectNum == 0)
                page[1].selectNum = page[1].data.size() - 2;
            else
                page[1].selectNum -= 1;
        }
        else if(m_key_pressed == KEY_DOWN)
        {
            if(page[1].selectNum == page[1].data.size() - 2)
                page[1].selectNum = 0;
            else
                page[1].selectNum += 1;
        }
        else if(m_key_pressed == KEY_ESC)
        {
            mozhu::log::Get()->writelog(1, "退出顾客详情");
            return;
        }
        else 
        {
            mozhu::log::Get()->writelog(0,"查看了"+users.users[page[1].selectNum - 1].ID+"顾客的订单");
            showorderlist(&users.users[page[1].selectNum - 1]);
        }
    }
}

void shop::showorderlist(user* ptr)
{
    if(ptr == nullptr)
        return;
    mozhu::log::Get()->writelog(1, "进入顾客订单列表页面");
    std::vector<_UI> page;

    _UI tittle;
    tittle.type = UI_str;
    tittle.addconststring("顾客订单列表页",1,6);
    page.emplace_back(tittle);

    _UI selector;
    selector.type = UI_selector;
    selector.specialSelector = -1;
    selector.selectNum = 0;
    std::vector<order*> list;
    for (int i = 0;i < orders.orders.size();i++)
    {
        if(orders.orders[i].customer->ID == ptr->ID)
        {
            list.emplace_back(&orders.orders[i]);
            selector.addconststring("订单号：");
            selector.addstr(&orders.orders[i].ordernumber);
            selector.addconststring("订单金额：");
            selector.addfloat(&orders.orders[i].totalprice);
        }
    }   
    page.emplace_back(selector);

    while(1)
    {
        clearUI();
        PrintUI(page);

        int m_key_pressed = KeyboardOperate();
        if(m_key_pressed == KEY_UP)
        {
            if(page[1].selectNum == 0)
                page[1].selectNum = page[1].data.size() - 1;
            else
                page[1].selectNum -= 1;
        }
        else if(m_key_pressed == KEY_DOWN)
        {
            if(page[1].selectNum == page[1].data.size() - 1)
                page[1].selectNum = 0;
            else
                page[1].selectNum += 1;
        }
        else if(m_key_pressed == KEY_ESC)
        {
            mozhu::log::Get()->writelog(1, "退出顾客详情");
            return;
        }
        else 
        {
            if(!list.empty())
            {
                showorderinfo(list[page[1].selectNum]);
            }
        }
    }
}

void shop::orderhistorypage()
{
    mozhu::log::Get()->writelog(1, "进入订单列表页面");
    std::vector<_UI> page;

    _UI tittle;
    tittle.type = UI_str;
    tittle.addconststring("顾客订单列表页",1,6);
    page.emplace_back(tittle);

    _UI selector;
    selector.type = UI_selector;
    selector.specialSelector = -1;
    for (int i = 0;i < orders.orders.size();i++)
    {
        selector.addconststring("订单号：");
        selector.addstr(&orders.orders[i].ordernumber);
        selector.addconststring("订单金额：");
        selector.addfloat(&orders.orders[i].totalprice);
    }   
    page.emplace_back(selector);

    while(1)
    {
        clearUI();
        PrintUI(page);

        int m_key_pressed = KeyboardOperate();
        if(m_key_pressed == KEY_UP)
        {
            if(page[1].selectNum == 0)
                page[1].selectNum = page[1].data.size() - 1;
            else
                page[1].selectNum -= 1;
        }
        else if(m_key_pressed == KEY_DOWN)
        {
            if(page[1].selectNum == page[1].data.size() - 1)
                page[1].selectNum = 0;
            else
                page[1].selectNum += 1;
        }
        else if(m_key_pressed == KEY_ESC)
        {
            mozhu::log::Get()->writelog(1, "退出订单列表");
            return;
        }
        else 
        {
            if(!orders.orders.empty())
            {
                showorderinfo(&orders.orders[page[1].selectNum]);
            }
        }
    }
}

void shop::orderstasticspage()
{
    int totalnumber = 0;
    for(order m_temp_order : orders.orders)
    {
        totalnumber += m_temp_order.totalprice;
    }
    while(1)
    {
        clearUI();
        std::cout << "总订单量：" << orders.orders.size() << std::endl;
        std::cout << "总订单金额:" << totalnumber << std::endl;

        int m_key_pressed = KeyboardOperate();
        if(m_key_pressed == KEY_ESC)
        {
            mozhu::log::Get()->writelog(1, "退出订单列表");
            return;
        }
    }
}

void shop::systemlogpage()
{
    clearUI();
    clearUI();
    mozhu::log::Get()->writelog(1, "进入系统日志列表");
    std::vector<logdata> data = mozhu::log::Get()->getlog();
    _UI page;
    
    for(int i = 0;i < data.size();i++)
    {
        logdata* m_templog = &data[i];

        int wordcolor = 0;
        int background = 0;
        if(m_templog->type == 0)
        {
            wordcolor = 2;
            background = 0;
        }
        else if(m_templog->type == 1)
        {
            wordcolor = 5;
            background = 2;
        }
        else if(m_templog->type == 2)
        {
            wordcolor = 6;
            background = 4;
        }
        page.addconststring("日志类型：",0,wordcolor,background);
        page.addint(&m_templog->type,1,wordcolor,background);
        page.addconststring("日志时间:",0,wordcolor,background);
        page.addint(&m_templog->timestamp.year,0,wordcolor,background);
        page.addconststring(",",0,wordcolor,background);
        page.addint(&m_templog->timestamp.month,0,wordcolor,background);
        page.addconststring(",",0,wordcolor,background);
        page.addint(&m_templog->timestamp.date,0,wordcolor,background);
        page.addconststring("    ",0,wordcolor,background);
        page.addint(&m_templog->timestamp.hour,0,wordcolor,background);
        page.addconststring(":",0,wordcolor,background);
        page.addint(&m_templog->timestamp.minute,0,wordcolor,background);
        page.addconststring(":",0,wordcolor,background);
        page.addint(&m_templog->timestamp.sec,1,wordcolor,background);
        page.addconststring("日志信息:",0,wordcolor,background);
        page.addstr(&m_templog->info,1,wordcolor,background);
        page.addconststring("",1);
        page.addconststring("",1);
    }
        
    page.show();
    int m_key_pressed = KeyboardOperate();
    if(m_key_pressed == KEY_ESC)
    {
        mozhu::log::Get()->writelog(1, "退出日志列表");
        return;
    }
}

void shop::adddatapage(user* ptr)
{
    if(ptr == nullptr)
        return;
    
    std::cout << "请输入用户昵称:" ;
    std::string name;
    std::cin >> name;
    if(!name.empty())
        ptr->name = name;
    ptr->subID = ptr->ID;
}

void shop::showorderinfo(order* ptr)
{
    mozhu::log::Get()->writelog(1, "进入订单详情");
    _UI page;

    page.addconststring("订单编号");
    page.addstr(&ptr->ordernumber,1);
    page.addconststring("订单金额");
    page.addfloat(&ptr->totalprice,1);
    for(ordercell m_temp_ordercell : ptr->data)
    {
        page.addstr(&m_temp_ordercell.databackup.name,1);
    }

    page.show();

    int m_key_pressed = KeyboardOperate();
    if(m_key_pressed == KEY_ESC)
    {
        mozhu::log::Get()->writelog(1, "退出订单列表");
        return;
    }
}